package code.timer;

import code.entity.Location;
import code.service.LocationService;
import code.util.URLUtil;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: cheny
 * Date: 12-3-3
 * Time: 下午1:39
 */
public class GPSToBaiduTimer implements Runnable {
    public void run() {
        try {
            while (true) {
                List<Location> list = LocationService.getNeedConvertLocationList();
                for (Location l : list) {
                    String json = URLUtil. convert(l.getLng(), l.getLat());
                    JSONObject jsonObject = new JSONObject(json);
                    String x = URLUtil.decode(jsonObject.getString("x"));
                    String y = URLUtil.decode(jsonObject.getString("y"));
                    System.out.println(x + "," + y);
                    LocationService.updateLocation(l.getId(), x, y);

                }
                Thread.sleep(1000 * 60 * 3);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
